package com.mhjy.input.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mhjy.input.service.INhSoMasterService;
import com.mhjy.input.repository.entity.NhSoMasterEntity;
import com.mhjy.input.repository.mapper.NhSoMasterMapper;
import com.mhjy.input.repository.model.BaseResultModel;
import com.mhjy.input.units.UnitHelper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class NhSoMasterService extends ServiceImpl<NhSoMasterMapper, NhSoMasterEntity> implements INhSoMasterService {
    @Override
    public BaseResultModel selectAll() {
        List<NhSoMasterEntity> list = baseMapper.selectAll();
        if (list != null && list.size() <= 0)
            return new BaseResultModel(99, "查询数据为空");
        else
            return new BaseResultModel(0, "", list);
    }

    @Override
    public BaseResultModel add(NhSoMasterEntity entity) {

        entity.setDcId(baseMapper.selectDcId());
        //entity.setDcId(4000000L + Long.valueOf(new Random().nextInt(900000) + 100000));//暂时的
        entity.setBatchNo(UnitHelper.GetBatchNo());
        entity.setId(1000000L + entity.getDcId());
        Integer k = baseMapper.insert(entity);
        return k > 0 ? new BaseResultModel(0, "成功") : new BaseResultModel(99, "失败");
    }
}
